﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using DevExpress.XtraBars.Ribbon;
using CNotebook.Inventory;
namespace NotebookS2
{
    public partial class StockMonitor : RibbonForm
    {
        public StockMonitor()
        {
            InitializeComponent();
        }
        public string ConnectionString { get; set; }
        void BindWarehouse()
        {
            WarehouseManager oManager = new WarehouseManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.GetWarehouse();

            oManager.Close();

            cboWarehouse.DisplayMember = "Dscription";
            cboWarehouse.ValueMember = "Code";

            cboWarehouse.DataSource = _table;

            cboWarehouse.Refresh();


        }


        public void PrintPreview()
        {
            if (!gridControl1.IsPrintingAvailable)
            {
                MessageBox.Show("The 'DevExpress.XtraPrinting' Library is not found", "Error");
                return;
            }
            // Opens the Preview window. 
            
            gridControl1.ShowPrintPreview();
        }

        void BindStocks(string _WhsCode)
        {
            StockManager oManager = new StockManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable _table = oManager.MonitorStocksByWarehouse(_WhsCode);

            gridControl1.DataSource = _table;
            gridControl1.Refresh();
            gridView1.ExpandAllGroups();
            oManager.Close();
        }
        private void StockMonitor_Load(object sender, EventArgs e)
        {
            BindWarehouse();
        }

        private void cboWarehouse_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindStocks(cboWarehouse.SelectedValue.ToString());
        }
    }
}
